//
//  MKBaseTableViewController.swift
//  101weibo
//
//  Created by 劢克科技 on 2019/1/18.
//  Copyright © 2019 劢克科技. All rights reserved.
//

import UIKit

class MKBaseTableViewController: UITableViewController {
    
    var isLogin = false
    
    lazy var visitorView = MKVisitorView()
    
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

//MARK: - 设置UI
extension MKBaseTableViewController {
    private func setupVisitorView() {
        self.view = visitorView
        
        visitorView.registBtn.addTarget(self, action: #selector(registClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(loginClick), for: .touchUpInside)
        
        setLeftNavBarItem()
        setRightNavBarItem()
    }
    
    private func setLeftNavBarItem() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(registClick))
    }
    
    private func setRightNavBarItem() {
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(loginClick))
    }
}


//MARK: - 事件
extension MKBaseTableViewController {
    @objc private func registClick() {
        print("regist")
    }
    
    @objc private func loginClick() {
        let oauthController = MKOAuthViewController()
        let navController = UINavigationController(rootViewController: oauthController)
        present(navController, animated: true, completion: nil)
    }
}
